package com.cuit.freshmanMS.controller;

import com.cuit.freshmanMS.VO.StudentVO;
import com.cuit.freshmanMS.domain.Student;
import com.cuit.freshmanMS.query.StudentQuery;
import com.cuit.freshmanMS.service.StudentService;
import com.cuit.freshmanMS.util.result.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: ziger
 * @time: 2024/1/19 16:13
 */
@RequestMapping("")
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    //删除
    @DeleteMapping("/student/{sid}")
    public CommonResult deleteBySno(@PathVariable("sid") String sid) {
        return studentService.deleteSno(sid) ? ResultUtil.success(true) : ResultUtil.fail(ResultCode.COMMON_FAIL);
    }
    //批量删除
    @RequestMapping("/student/batchDelete")
    public CommonResult batchDelete(@RequestBody List<String> snos) {
        return studentService.batchDelete(snos) ? ResultUtil.success(true) : ResultUtil.fail(ResultCode.COMMON_FAIL);
    }

    //增加
    @PostMapping("/student")
    public CommonResult add(@RequestBody Student student) {//@RequestBody 将JSON格式变为指定的对象格式
        return studentService.addstu(student) ? ResultUtil.success(true) : ResultUtil.fail(ResultCode.COMMON_FAIL);
    }

    //修改
    @PutMapping("/student")
    public CommonResult update(@RequestBody Student student) {
        return studentService.updatete(student) ? ResultUtil.success(true) : ResultUtil.fail(ResultCode.COMMON_FAIL);
    }

    //分页查询
    @PostMapping("/student/pageQuery")
    public PageResult<StudentVO> pageQuery(@RequestBody StudentQuery studentQuery) {
        return studentService.pageQuery(studentQuery);
    }

}
